/*
 * 文件名：AppListener.java
 * 版权：Copyright by will_awoke
 * 描述：
 * 修改人：lyh
 * 修改时间：2014-3-25
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */

package com.qbgs.listener;


import javax.servlet.ServletContextEvent;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.qbgs.util.SystemTimer;


/**
 * 
 * AppListener
 * 
 * @author will_awoke
 * @version 2014-3-25
 * @see AppListener
 * @since
 */
public class AppListener extends ContextLoaderListener
{

    /**
     * 日志
     */
    private static final Log logger = LogFactory.getLog(AppListener.class);

    /**
     * 系统的上下文
     */
    public static WebApplicationContext ctx;

    /**
     * 初始化上下文
     */
    public void contextInitialized(ServletContextEvent event)
    {
        super.contextInitialized(event);

        //获取当前的上下文
        ctx = WebApplicationContextUtils.getWebApplicationContext(event.getServletContext());
        logger.info("AppListener # context has been initialized... ");
    }

    /**
     * 销毁上下文
     */
    public void contextDestroyed(ServletContextEvent event)
    {
        //close ScheduledExecutorService in web container
        SystemTimer.shutdownScheduledExecutor();
        super.contextDestroyed(event);
        logger.info("AppListener # context destroyed... ");
    }

}
